<template>
  <view class="base-chart">
    <LEchart class="h-100% w-100%" ref="chartRef" />
  </view>
</template>

<script setup>
import LEchart from '@/uni_modules/lime-echart/components/l-echart/l-echart.vue'
import { nextTick, onMounted, ref, watch } from 'vue'

// #ifdef MP
const echarts = require('../uni_modules/lime-echart/static/echarts.min')
// #endif

const props = defineProps({
  options: {
    type: Object,
    default: () => ({}),
  },
})

const chartRef = ref(null)

const initData = async (data) => {
  await nextTick()
  if (chartRef.value) {
    console.log('chartRef', chartRef.value)
    const myChart = await chartRef.value.init(echarts)
    myChart.setOption(data)
  }
}

onMounted(() => {
  setTimeout(() => {
    initData(props.options)
  }, 200)
})

watch(
  () => props.options,
  (newValue) => {
    initData(newValue)
  },
  {
    deep: true,
  },
)
</script>

<style lang="scss" scoped>
.base-chart {
  width: 100%;
  height: 100%;
}
</style>
